<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字符出现次数最多的字符</title>
</head>

<body>
    <script>
        //利用chartAt（） 遍历字符

        var str = "adfgcadafad"
        var a = {}
        for (let i = 0; i < str.length; i++) {
            var asd = str.charAt(i) //asd 字符串里的每一个字符
            //判断这个对象是否存在，没存在加1，存在加加
            if (a[asd]) {
                a[asd]++
            } else {
                a[asd] = 1
            }
        }
        console.log(a);
        //遍历对象
        var max = 0
        var name = ''
        for (var k in a) {
            //k属性名
            //a[k] 属性值
            if (a[k] > max) {
                max = a[k]
                name = k
            }
        }
        console.log('出现的次数最多个字符是', name, "出现的次数", max);

        //substr('截取起始位置',"截取几个字符")
        var straaa = '改革春风吹满地'
        console.log(straaa.substr(2, 2));

        //替换字符replace('被替换的字符',"替换成的字符")  它只会替换第一个字符
        var asd = 'qwert'
        console.log(asd.replace('e', "9"));

        //循环多个替换
        var asd = "asdsdsdffffgggghhh"
        while (asd.indexOf("g") !== -1) {
            asd = asd.replace('g', "2")
        }
        console.log(asd);

        //把字符转换成数组
        var qwe = 'qwer,wer,as,df,xvc,rty'
        console.log(qwe.split(','));

    </script>
</body>

</html>